{% extends "zato/index.html" %}

{% block html_title %}Servers{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
    <style type="text/css">
        .ui-dialog-titlebar {
            padding-bottom:10px !important;
        }
    </style>
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/cluster_servers.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            'name',
            'host',
            'up_status',
            'up_mod_date',
            'lb_state',
            'lb_address',
            '_add_remove_lb',
            '_edit',
            '_delete',
            'id',
            'old_name',
            'in_lb',
            'may_be_deleted',
        ]
    }

    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Clusters : {% if cluster %}<a href='{% url "cluster" %}?highlight={{ cluster.id }}'>{{ cluster.name }}</a> :{% endif %} Servers</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

{% include "zato/search-form.html" with page_prompt="Show servers"%}


    {% if cluster.id %}

        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Server host/FQDN</a></th>
                        <th><a href="#">Server state</a></th>
                        <th><a href="#">Server state update</a></th>
                        <th><a href="#">LB state</a></th>
                        <th><a href="#">LB address</a></th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.host|default:'(unknown)' }}</td>
                        <td>{{ item.up_status|default:'(unknown)' }}</td>
                        <td>{{ item.up_mod_date_user|default:'(unknown)' }}</td>
                        <td>{{ item.lb_state|default:'(unknown)' }}</td>
                        <td>{{ item.lb_address|default:'(unknown)' }}</td>
                        <td>
                            {% if False %}
                                {% if item.in_lb %}
                                    <a href="javascript:$.fn.zato.cluster.servers.add_remove_lb('remove', '{{ item.id }}', '{{ cluster.id }}')">Remove from LB</a>
                                {% else %}
                                    <a href="javascript:$.fn.zato.cluster.servers.add_remove_lb('add', '{{ item.id }}', '{{ cluster.id }}')">Add to LB</a>
                                {% endif %}
                            {% endif %}
                        </td>
                        <td>
                            {% if False %}
                                <a href="javascript:$.fn.zato.cluster.servers.edit('{{ item.id }}')">Edit</a>
                            {% endif %}
                        </td>
                        <td>
                            {% if False %}
                                {% if item.may_be_deleted %}
                                    <a href="javascript:$.fn.zato.cluster.servers.delete_('{{ item.id }}')">Delete</a>
                                {% endif %}
                            {% endif %}
                        </td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>
                        <td class='ignore'>{{ item.name }}</td>
                        <td class='ignore'>{{ item.in_lb }}</td>
                        <td class='ignore'>{{ item.may_be_deleted }}</td>
                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='13'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "cluster-servers-edit" %}" method="post" id="edit-form">
                    <table class="form-data">

                        <tr>
                            <td style="vertical-align:middle;width:10%">Name</td>
                            <td>
                                {{ edit_form.name }}
                                {{ edit_form.old_name }}
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" id="cluster_id" name="ignored" value="{{ cluster.id }}" />
                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster.id }}" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>

    {% endif %}


{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
